<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.lmpop.trade.ti_teambuy.*"%>
<%@page import="java.util.*"%>
<%@page import="com.lmpop.trade.ts_category.*"%>
<%@page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo"%>
<%@page import="java.net.URLDecoder"%>

<html>
	<head>
		<title>团购管理</title>
		<link href="/program/admin/index/css/style.css" rel="stylesheet"
			type="text/css">
		<link href="/program/admin/index/css/thickbox.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="/js/thickbox.js"></script>
		<script language="javascript" type="text/javascript"
			src="/program/plugins/calendar/WdatePicker.js"></script>
	 <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ts_categoryInfo.js'></script>
	<script type="text/javascript" src="index.js"></script>

	</head>

	<body >
		<%
			String info_id = "";
			if (request.getParameter("info_id") != null)
				info_id = request.getParameter("info_id");
			Ti_teambuyInfo ti_teambuyInfo = new Ti_teambuyInfo();
			List list = ti_teambuyInfo.getListByPk(info_id);
			Hashtable map = new Hashtable();
			if (list != null && list.size() > 0)
				map = (Hashtable) list.get(0);

			String vmoney="",input_price="",weight="",price_unit="",cat_attr="",tuihuo="",is_freeshipping="",cash_on_delivery="",cur_store="",title = "", type = "", team_type = "", price = "", old_price = "", start_date = "", end_date = "", team_num = "", limit_num = "", down_num = "", state = "", tip = "", highlight = "", content = "", seller = "", contact = "", buy_limit = "", user_id = "", in_date = "";
			if(map.get("weight")!=null) weight = map.get("weight").toString();
			if(map.get("price_unit")!=null) price_unit = map.get("price_unit").toString();
			if (map.get("cur_store") != null)
				cur_store = map.get("cur_store").toString();
			if (map.get("is_freeshipping") != null)
				is_freeshipping = map.get("is_freeshipping").toString();
			if (map.get("tuihuo") != null)
				tuihuo = map.get("tuihuo").toString();
			if (map.get("cash_on_delivery") != null)
				cash_on_delivery = map.get("cash_on_delivery").toString();
			if (map.get("vmoney") != null)
				vmoney = map.get("vmoney").toString();
			if (map.get("title") != null)
				title = map.get("title").toString();
			if (map.get("type") != null)
				type = map.get("type").toString();
			if (map.get("team_type") != null)
				team_type = map.get("team_type").toString();
			if (map.get("price") != null)
				price = map.get("price").toString();
			if (map.get("input_price") != null)
				input_price = map.get("input_price").toString();
			if (map.get("old_price") != null)
				old_price = map.get("old_price").toString();
			if (map.get("start_date") != null)
				start_date = map.get("start_date").toString();
			if (start_date.length() > 19)
				start_date = start_date.substring(0, 19);
			if (map.get("end_date") != null)
				end_date = map.get("end_date").toString();
			if (end_date.length() > 19)
				end_date = end_date.substring(0, 19);
			if (map.get("team_num") != null)
				team_num = map.get("team_num").toString();
			if (map.get("limit_num") != null)
				limit_num = map.get("limit_num").toString();
			if (map.get("down_num") != null)
				down_num = map.get("down_num").toString();
			if (map.get("state") != null)
				state = map.get("state").toString();
			if (map.get("tip") != null)
				tip = map.get("tip").toString();
			if (map.get("highlight") != null)
				highlight = map.get("highlight").toString();
			if (map.get("content") != null)
				content = map.get("content").toString();
			if (map.get("seller") != null)
				seller = map.get("seller").toString();
			if (map.get("contact") != null)
				contact = map.get("contact").toString();
			if (map.get("buy_limit") != null)
				buy_limit = map.get("buy_limit").toString();
			if (map.get("user_id") != null)
				user_id = map.get("user_id").toString();
			StringBuffer catattr=new StringBuffer();
			Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
			if (map.get("cat_attr") != null){
					cat_attr = map.get("cat_attr").toString();
						 if(!cat_attr.equals("")){
							  String cat_attrIds[] = cat_attr.split("\\|");	
							  for(String catId:cat_attrIds){
									catattr.append(ts_categoryInfo.getCat_nameById(catId)+"&nbsp;");
								  }                 
							}
				}
		
			String selecttree = ts_categoryInfo.getCategoryTree(
					"000000000000000", "13",team_type);
			Map catMap = ts_categoryInfo.getCatClassMap("12");
			StringBuffer output = new StringBuffer();
			if (!team_type.equals("")) {
				String chIds[] = team_type.split("\\|");
				for (String chId : chIds) {
					if (catMap != null) {
						if (catMap.get(chId) != null) {
							output.append(catMap.get(chId).toString() + " ");
						}

					}
				}
			}
			
	String req_title="";
	String req_state="";

	if(request.getParameter("req_title")!=null && !request.getParameter("req_title").equals("")){
		req_title = request.getParameter("req_title");
	}
	
	if(request.getParameter("req_state")!=null && !request.getParameter("req_state").equals("")){
		req_state = request.getParameter("req_state");
	}
	
	String teamType = "";
	if(request.getParameter("teamType")!=null && !request.getParameter("teamType").equals("")){
		teamType = request.getParameter("teamType");
	}
	
	String iStart = "0";
	if(request.getParameter("iStart")!=null && !request.getParameter("iStart").equals("")){
		iStart = request.getParameter("iStart");
	}
	
	String url ="/program/admin/teambuy/index.jsp?teamType="+teamType+"&req_state="+req_state+"&teamType="+teamType+"&iStart="+iStart;
	  Tb_commparaInfo tb_commparaInfo = new Tb_commparaInfo(); 
	 String s_price_unit = tb_commparaInfo.getSelectItem("18",price_unit); 
	 
	 String cust_id="",shop_name1="",shop_addr1="",shop_phone1="",shop_web1="";
	
	if(request.getParameter("cust_id") != null) {
		 cust_id = request.getParameter("cust_id").trim();
	}
	if(request.getParameter("seller") != null) {
		 seller = URLDecoder.decode(request.getParameter("seller"),"UTF-8");
	}
	if(request.getParameter("shop_name1") != null) {
		 shop_name1 = URLDecoder.decode(request.getParameter("shop_name1"),"UTF-8");
	}
	if(request.getParameter("shop_addr1") != null) {
		 shop_addr1 = URLDecoder.decode(request.getParameter("shop_addr1"),"UTF-8");
	}
	if(request.getParameter("shop_phone1") != null) {
		 shop_phone1 = request.getParameter("shop_phone1").trim();
	}
	if(request.getParameter("shop_web1") != null) {
		 shop_web1 = URLDecoder.decode(request.getParameter("shop_web1"),"UTF-8");
	}
	%>

		<h1>
			修改团购
		</h1>


		<table width="100%" align="center" cellpadding="0" cellspacing="0"
			class="dl_so">
			<tr>
				<td width="9%" align="center">
					<img src="/program/admin/index/images/ban_01.gif" />
				</td>
				<td width="91%" align="left">
					<h4>
						团购类型的解释
					</h4>
					<span>团购券交易：买家付款后获取商家提供的券和密码，用于领取商品。</span>
					<br />
					<span>邮购交易：买家购买商品需提供收货地址，卖家快递发送商品给买家。</span>
					<br />
					<span>限购数量为0则不限制购买数量。</span>
				</td>
			</tr>
		</table>
		<br />

		<form action="/doTradeReg.do" method="post" name="updateForm">

			<input name="info_id" id="info_id" type="hidden" value="<%=info_id%>" />

			<table width="100%" cellpadding="0" cellspacing="1" border="0"
				class="listtab">
			<tr>
					<td align="right" width="10%">
						卖家名称
						<font color="red">*</font>
					</td>
					<td colspan="3">
						<div id="_seller">
							<input name="seller" id="seller" value="<%=seller %>"  size="50" maxlength="50" type="text" />
							<input type="button" class="button_s_css" value=" 搜索 "  onclick="showLinkCompany('update')" />
						</div>
						<div id="show_seller" style="display: none">
							<select name="sort11" id="sort11" onclick="setSecondClass(this.value,'1','sort22','sort33');" >
										  <option value="">请选择</option>
							</select>	
							<select name="sort22" id="sort22" onclick="setTherdClass(this.value,'1','sort33');">
										  <option value="">请选择</option>
							</select>	
							<select name="sort33" id="sort33" >
										  <option value="">请选择</option>
							</select>
							<input type="button" class="button_s_css" value=" 搜索 "  onclick="showLinkCompany('update')" />	
						</div>
					</td>
				</tr>
				<tr>
						<td align="right" width="10%">
							卖家联系方式<font color="red">*</font>
						</td>
						<td colspan="3">
							<input name="contact" id="contact" type="hidden" />
									<input name="contact" id="contact" type="button" value="添加联系地址"
										onclick="addContact()" style="cursor: pointer;" />
				<%if(shop_name1!=null&&!shop_name1.equals("")) {%>
							<input name="con_num" id="con_num" type="hidden" value="2"/>
									<div id="contactDiv">
										<div id="div_shop1">
											店名：<input type="text" name="shop_name1" value="<%=shop_name1 %>" id="shop_name1" size="30" maxlength="50"/>&nbsp;<br/>
											地址：<input type="text" name="shop_addr1" value="<%=shop_addr1 %>" id="shop_addr1" size="50" maxlength="60"/><br/>
											电话号码：<input type="text" name="shop_phone1" value="<%=shop_phone1 %>" id="shop_phone1" size="20" maxlength="20"/>&nbsp;网址：<input type="text" name="shop_web1" id="shop_web1" size="20" maxlength="20"/>&nbsp;
											<a href="javascript:delContact(1)">删除</a>&nbsp;<br/>
										</div>
									</div>
							
					
				<%}else{
							String contactStr[] = contact.split(",");
							int c_size = contactStr.length + 1;
						%>
						<input name="con_num" id="con_num" type="hidden"
							value="<%=c_size%>" />
						<div id="contactDiv">

							<%
								for (int j = 0; j < c_size - 1; j++) {
									String shop_name = "", shop_addr = "", shop_phone = "", shop_web = "";
									String son_con[] = contactStr[j].split("\\|");
									if (son_con.length > 0)
										shop_name = son_con[0];
									if (son_con.length > 1)
										shop_addr = son_con[1];
									if (son_con.length > 2)
										shop_phone = son_con[2];
									if (son_con.length > 3)
										shop_web = son_con[3];
									int i = j + 1;
							%>
							<div id="div_shop<%=i%>">
								店名：
								<input type="text" name="shop_name<%=i%>" id="shop_name<%=i%>"
									size="30" maxlength="50" value="<%=shop_name%>" />
								&nbsp;<br/>地址：
								<input type="text" name="shop_addr<%=i%>" id="shop_addr<%=i%>"
									size="50" maxlength="60" value="<%=shop_addr%>" />
								<br />
								电话号码：
								<input type="text" name="shop_phone<%=i%>" id="shop_phone<%=i%>"
									size="20" maxlength="20" value="<%=shop_phone%>" />
								&nbsp;网址：
								<input type="text" name="shop_web<%=i%>" id="shop_web<%=i%>"
									size="20" maxlength="20" value="<%=shop_web%>" />
								&nbsp;
								<a href="javascript:delContact(<%=i%>)">删除</a>&nbsp;<br/>
								<br />
							</div>
							<%
								}
							%>
						</div>

				<%}%>
					</td>
				</tr>
				<tr>
					<td align="right" width="10%">
						标题
						<font color="red">*</font>
					</td>
					<td colspan="3">
						<textarea name="title" id="title"
							style="width: 640px; height: 60px;"><%=title%></textarea>
						<br />
						（字数限制在300字以内）
					</td>
				</tr>

				 <tr>
			<td align="right" width="15%">
				商品缩略图:			
			</td>
			<td >
			 <jsp:include page="/program/inc/uploadImgInc.jsp">
					<jsp:param name="attach_root_id" value="<%=info_id%>" />
					<jsp:param name="img_type" value="1" />
				</jsp:include>

			
			</td>
			<td align="right" width="15%">
				商品分类:
			</td>
			<td >
				<p><%=catattr %>
							<input type="button" class="buttoncss" name="" value="修改"
								onclick="showDiv(1)" />
							</p>
				<div id="cat_div" style="display: none;">
					  <select name="sort1" id="sort1" onclick="setSecondClass(this.value,'2','sort2','sort3');" >
							  <option value="">请选择</option>
					</select>	
					<select name="sort2" id="sort2" onclick="setTherdClass(this.value,'2','sort3');">
								  <option value="">请选择</option>
					</select>	
					<select name="sort3" id="sort3" >
								  <option value="">请选择</option>
					</select>	
				</div>			
			</td>
		</tr> 
	<tr>
				<td align="right" width="15%">
					进价：<font color="red">*</font>
				</td>
				<td><input name="input_price" id="input_price" size="8" maxlength="8" type="text" value="<%=input_price %>" onKeyUp="if(isNaN(value))this.value=''"/></td>
			
				<td align="right" width="10%">
					当前库存：<font color="red">*</font>
				</td>
				<td><input name="cur_store" id="cur_store" size="8" maxlength="8" type="text" value="<%=cur_store %>" onKeyUp="if(isNaN(value))this.value=''"/></td>
			
		</tr>
				<tr>
					<td align="right" width="15%">
						团购类型
						<font color="red">*</font>
					</td>
					<td align="left">
						<input type="hidden" id="s_team_type" name="s_team_type"
							value="<%=team_type%>" />
						<input type="hidden" id="flag_code" name="flag_code" value="0" />
						<div id="classId2" >
							<table cellspacing="0" cellpadding="0" border="0" align="left"
								class="listtab1">
								<tr>
									<td colspan="3">
										<select name="team_type" id="team_type">
											<option value="">请选择</option>
											<%=selecttree%>
										</select>
									</td>
								</tr>
							</table>
						</div>
					</td>
					<td align="right" width="10%">
						交易类型:
					</td>
					<td>
						<select name="type" id="type">
							<option value="1"
								<%if(type.equals("1")) out.println("selected");%>>
								团购券交易
							</option>
							<option value="2"
								<%if(type.equals("2")) out.println("selected");%>>
								邮购交易
							</option>
						</select>
					</td>
				</tr>
			
			<tr>
			<td align="right" width="15%">
				商品重量<font color="red">*</font>
			</td>
			<td >
				 <input type="text" name="weight" id="weight" size="15" value="<%=weight %>" maxlength="10"  onkeyup= "{if(this.value== ' ')this.value= '0 ';if((/^((\d+)(\.\d{0,1})?)?$/).test(this.value))   this.oldValue=this.value;   else   this.value=this.oldValue;} "/>千克
			</td>
			<td align="right" width="15%">
				计价单位<font color="red">*</font>
			</td>
			<td >
			   <select name="price_unit" id="price_unit">
	            <option value="">请选择</option>
	             <%=s_price_unit%>           
	            </select>           
			</td>
		</tr>
		
				<tr>

					<td align="right" width="10%">
						限购数量
						<font color="red">*</font>
					</td>
					<td>
						<input name="limit_num" id="limit_num" size="8" maxlength="8"
							type="text" value="<%=limit_num%>" onKeyUp="if(isNaN(value))this.value=''"/>
					</td>
					<td align="right" width="15%">
				是否允许退货:
			</td>
			<td>
				<input name="tuihuo" id="tuihuo1"  type="radio" value="0" <%if(tuihuo.equals("0")) out.print("checked");%>/>不允许
				<input name="tuihuo" id="tuihuo2"  type="radio" value="1"  <%if(tuihuo.equals("1")) out.print("checked");%>/>允许
			</td>
				</tr>

				<tr>
					<td align="right" width="10%">
						价格
						<font color="red">*</font>
					</td>
					<td>
						<input name="price" id="price" size="8" maxlength="8" type="text"
							value="<%=price%>" onkeyup= "{if(this.value== ' ')this.value= '0 ';if((/^((\d+)(\.\d{0,1})?)?$/).test(this.value))   this.oldValue=this.value;   else   this.value=this.oldValue;} " />
					</td>
					<td align="right" width="10%">
						原价
						<font color="red">*</font>
					</td>
					<td>
						<input name="old_price" id="old_price" size="8" maxlength="8"
							type="text" value="<%=old_price%>" onkeyup= "{if(this.value== ' ')this.value= '0 ';if((/^((\d+)(\.\d{0,1})?)?$/).test(this.value))   this.oldValue=this.value;   else   this.value=this.oldValue;} " />
					</td>
				</tr>


				<tr>
					<td align="right" width="10%">
						开始时间
						<font color="red">*</font>
					</td>
					<td>
						<input id="start_date" name="start_date" type="text" class="Wdate"
							value="<%=start_date%>"
							onclick="WdatePicker({maxDate:'#F{$dp.$D(\'end_date\',{d:-1})}',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
					</td>
					<td align="right" width="10%">
						结束时间
						<font color="red">*</font>
					</td>
					<td>
						<input id="end_date" name="end_date" type="text" class="Wdate"
							value="<%=end_date%>"
							onclick="WdatePicker({minDate:'#F{$dp.$D(\'start_date\',{d:1})}',dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
					</td>
				</tr>

				<tr>
					<td align="right" width="10%">
						最低团购人数
						<font color="red">*</font>
					</td>
					<td>
						<input name="down_num" id="down_num" size="8" maxlength="8"
							type="text" value="<%=down_num%>" onKeyUp="if(isNaN(value))this.value=''"/>
					</td>
					<td align="right" width="10%">
						单次限购数量
						<font color="red">*</font>
					</td>
					<td colspan="3">
						<input name="buy_limit" id="buy_limit" size="8" maxlength="8"
							type="text" value="<%=buy_limit%>" onKeyUp="if(isNaN(value))this.value=''"/>
					</td>

				</tr>
<!-- 
<tr>
			<td align="right" width="15%">
				是否免运费
			</td>
			<td>
				<input name="is_freeshipping" type="radio" value="1" <%if(is_freeshipping.equals("1")) out.print("checked");%>/>是
				<input name="is_freeshipping" type="radio" value="0" <%if(is_freeshipping.equals("0")) out.print("checked");%>/>否
			</td>
			<td align="right" width="15%">
				货到付款
			</td>
			<td colspan="3">
				<input name="cash_on_delivery" type="radio" value="1" <%if(cash_on_delivery.equals("1")) out.print("checked");%>/>是
				<input name="cash_on_delivery" type="radio" value="0" <%if(cash_on_delivery.equals("0")) out.print("checked");%>/>否
			</td>
			
		</tr>
 -->
				<tr>
					<td align="right" width="10%">
						提示:
					</td>
					<td colspan="3">
						<textarea name="tip" id="tip" style="width: 417px; height: 147px;"><%=tip%></textarea>
					</td>
				</tr>
					<tr>
				<td align="right" width="10%">
						亮点:
					</td>
					<td colspan="3">
						<textarea name="highlight" id="highlight"
							style="width: 417px; height: 147px;"><%=highlight%></textarea>
					</td>
				</tr>
				<tr>
					<td align="right" width="10%">
						团购详细
						<font color="red">*</font>
					</td>
					<td colspan="3">
						<textarea name="content" id="content"><%=content%></textarea>
						<script type="text/javascript"
							src="/program/plugins/ckeditor/ckeditor.js"></script>
						<script type="text/javascript">
				 CKEDITOR.replace( 'content',{
			   	      filebrowserUploadUrl : '/program/inc/upload.jsp?type=file&attach_root_id=<%=info_id%>',      
                      filebrowserImageUploadUrl : '/program/inc/upload.jsp?type=img&attach_root_id=<%=info_id%>',      
                      filebrowserFlashUploadUrl : '/program/inc/upload.jsp?type=flash&attach_root_id=<%=info_id%>'     
                 });  
			</script>
					</td>
				</tr>
			
			</table>

			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td align="center">
						<input type="hidden" name="cat_attr" id="cat_attr" value="<%=cat_attr %>"/>		
						<input name="user_id" id="user_id" type="hidden"
							value="<%=cust_id%>" />
						<input name="user_idbak" id="user_idbak" type="hidden"
							value="<%=user_id%>" />
						<input name="team_num" id="team_num" value="<%=team_num%>"
							type="hidden" />
							<input name="vmoney" id="vmoney" value="<%=vmoney%>"
							type="hidden" />
						<input name="_cur_store" id="_cur_store" value="<%=cur_store%>"
							type="hidden" />
						<input type="hidden" name="is_freeshipping" value="0" />
						<input type="hidden" name="cash_on_delivery" value="0" />
						<input type="hidden" name="bpm_id" value="2446" />
						<input type="button" class="buttoncss" name="tradeSub" value="提交"
							onclick="return checkSub('update');" />
						&nbsp;&nbsp;
						<input type="button" class="buttoncss" name="tradeRut" value="返回"
							onclick="window.location.href='<%=url%>';" />
					</td>
				</tr>
			</table>
		</form>
			<script type="text/javascript">
	setOneClass('2','sort1');
	setOneClass('1','sort11');
	</script>
	</body>

</html>
